<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:a4j="http://richfaces.org/a4j"
	xmlns:rich="http://richfaces.org/rich">

<ui:composition template="/main-template.xhtml">

<ui:define name="menu">

		<h:form>

			<rich:toolBar styleClass="toolBar">

				<rich:dropDownMenu>
					<f:facet name="label">
						<h:panelGroup>
							<h:outputText value="#{msg.label_users}" />
						</h:panelGroup>
					</f:facet>
					<rich:menuItem submitMode="ajax" value="#{msg.manageUsers}"
						action="users">
						<f:setPropertyActionListener value="list"
							target="#{userBean.currentState}"></f:setPropertyActionListener>
					</rich:menuItem>
					<rich:menuItem submitMode="ajax" value="#{msg.newUser}"	action="#{userBean.prepareCreate}">
						<f:setPropertyActionListener value="create"	target="#{userBean.currentState}"></f:setPropertyActionListener>
					</rich:menuItem>
				</rich:dropDownMenu>

				<rich:dropDownMenu>
					<f:facet name="label">
						<h:panelGroup>
							<h:outputText value="#{msg.label_process}" />
						</h:panelGroup>
					</f:facet>
					<rich:menuItem submitMode="ajax" value="#{msg.manageProcesses}" action="process">
						<f:setPropertyActionListener target="#{processBean.currentState}" value="list"/>
					</rich:menuItem>
					<rich:menuItem submitMode="ajax" value="#{msg.newProcess}" action="#{processBean.prepareCreate}">
						<f:setPropertyActionListener target="#{processBean.currentState}" value="create"/>
					</rich:menuItem>
				</rich:dropDownMenu>

			</rich:toolBar>

		</h:form>


	</ui:define>

	<ui:define name="content">
		<a4j:outputPanel id="create" rendered="#{processBean.currentState == 'create'}">
		
			<h1><h:outputText value="#{msg.process_page_title}" /></h1>
			<rich:panel>
			<h:form>
			<h:panelGrid columns="2" cellspacing="4">
					
					<h:outputLabel value="#{msg.process_name}" />
					<h:panelGroup>
						<h:inputText id="process_name" value="#{processBean.name}" required="true" />
						<rich:message for="process_name">
								<f:facet name="passedMarker">
									<h:graphicImage value="/images/passed.png" />
								</f:facet>
								<f:facet name="errorMarker">
									<h:graphicImage value="/images/error.png" />
								</f:facet>
						</rich:message>
					</h:panelGroup>

					<h:outputLabel value="#{msg.process_number}" />
					<h:panelGroup>
						<h:inputText id="process_number" value="#{processBean.number}" required="true"/>
						<rich:message for="process_number">
							<f:facet name="passedMarker">
								<h:graphicImage value="/images/passed.png" />
							</f:facet>
							<f:facet name="errorMarker">
								<h:graphicImage value="/images/error.png" />
							</f:facet>
						</rich:message>
					</h:panelGroup>
					
					<h:outputLabel value="#{msg.process_part}" />
					<h:panelGroup>
						<h:selectOneMenu  value="#{processBean.user}" converter="usersConverter" required="true" id="process_owner"   >
							<f:selectItems value="#{userBean.listAllUsers}" />
						</h:selectOneMenu>
						<rich:message for="process_owner">
							<f:facet name="passedMarker">
								<h:graphicImage value="/images/passed.png" />
							</f:facet>
							<f:facet name="errorMarker">
								<h:graphicImage value="/images/error.png" />
							</f:facet>
						</rich:message>
					</h:panelGroup>
					
					<h:outputText value ="#{msg.process_status}" />
					<h:panelGroup>
						<h:selectOneMenu id="status" value="#{processBean.status}">
							<f:selectItem id="iniciated" itemLabel="#{msg.process_status_iniciated}"
								itemValue="iniciated" />
							<f:selectItem id="ongoing" itemLabel="#{msg.process_status_ongoing}"
								itemValue="ongoing" />
							<f:selectItem id="finished" itemLabel="#{msg.process_status_finished}" 
								itemValue="finished" />
						</h:selectOneMenu>
						<rich:message for="status">
							<f:facet name="passedMarker">
								<h:graphicImage value="/images/passed.png" />
							</f:facet>
							<f:facet name="errorMarker">
								<h:graphicImage value="/images/error.png" />
							</f:facet>
						</rich:message>
					</h:panelGroup>
						
					<h:outputLabel value="#{msg.process_solicitation}" />
					<h:panelGroup>
						<h:inputTextarea id="process_solicitation" value="#{processBean.solicitation}" style="width:147px" required="true" />
						<rich:message for="process_solicitation">
							<f:facet name="passedMarker">
								<h:graphicImage value="/images/passed.png" />
							</f:facet>
							<f:facet name="errorMarker">
								<h:graphicImage value="/images/error.png" />
							</f:facet>
						</rich:message>
					</h:panelGroup>
					
					<h:panelGroup />
						<h:panelGroup />
						<h:panelGroup>
							<a4j:commandButton value="#{msg.process_bt_send}"
								action="#{processBean.createAction}">
								<f:setPropertyActionListener target="#{processBean.currentState}"
									value="list" />
							</a4j:commandButton>

							<a4j:commandButton value="#{msg.cancel}" action="process"
								immediate="true">
								<f:setPropertyActionListener target="#{processBean.currentState}"
									value="list"></f:setPropertyActionListener>
							</a4j:commandButton>
						</h:panelGroup>
				</h:panelGrid>
			</h:form>
			</rich:panel>
		</a4j:outputPanel>
		
		<a4j:outputPanel id="edit" rendered="#{processBean.currentState == 'edit'}">
		
			<h1><h:outputText value="#{msg.process_edit_title}" /></h1>
			<rich:panel>
			<h:form>
			<h:panelGrid columns="2" cellspacing="4">
					
					<h:outputLabel value="#{msg.process_name}" />
					<h:panelGroup>
						<h:inputText id="process_name" value="#{processBean.name}" required="true" />
						<rich:message for="process_name">
								<f:facet name="passedMarker">
									<h:graphicImage value="/images/passed.png" />
								</f:facet>
								<f:facet name="errorMarker">
									<h:graphicImage value="/images/error.png" />
								</f:facet>
						</rich:message>
					</h:panelGroup>

					<h:outputLabel value="#{msg.process_number}" />
					<h:panelGroup>
						<h:inputText id="process_number" value="#{processBean.number}" required="true"/>
						<rich:message for="process_number">
							<f:facet name="passedMarker">
								<h:graphicImage value="/images/passed.png" />
							</f:facet>
							<f:facet name="errorMarker">
								<h:graphicImage value="/images/error.png" />
							</f:facet>
						</rich:message>
					</h:panelGroup>
					
					<h:outputLabel value="#{msg.process_part}" />
					<h:panelGroup>
						<h:selectOneMenu value="#{processBean.user}" converter="usersConverter" required="true" id="process_owner" >
							<f:selectItems value="#{userBean.listAllUsers}" />
						</h:selectOneMenu>
						<rich:message for="process_owner">
							<f:facet name="passedMarker">
								<h:graphicImage value="/images/passed.png" />
							</f:facet>
							<f:facet name="errorMarker">
								<h:graphicImage value="/images/error.png" />
							</f:facet>
						</rich:message>
					</h:panelGroup>
					
					<h:outputText value ="#{msg.process_status}" />
					<h:panelGroup>
						<h:selectOneMenu id="status" value="#{processBean.status}">
							<f:selectItem id="iniciated" itemLabel="#{msg.process_status_iniciated}"
								itemValue="#{msg.process_status_iniciated}" />
							<f:selectItem id="ongoing" itemLabel="#{msg.process_status_ongoing}"
								itemValue="#{msg.process_status_ongoing}" />
							<f:selectItem id="finished" itemLabel="#{msg.process_status_finished}" 
								itemValue="#{msg.process_status_finished}" />
						</h:selectOneMenu>
						<rich:message for="status">
							<f:facet name="passedMarker">
								<h:graphicImage value="/images/passed.png" />
							</f:facet>
							<f:facet name="errorMarker">
								<h:graphicImage value="/images/error.png" />
							</f:facet>
						</rich:message>
					</h:panelGroup>
						
					<h:outputLabel value="#{msg.process_solicitation}" />
					<h:panelGroup>
						<h:inputTextarea id="process_solicitation" value="#{processBean.solicitation}" style="width:147px" required="true" />
						<rich:message for="process_solicitation">
							<f:facet name="passedMarker">
								<h:graphicImage value="/images/passed.png" />
							</f:facet>
							<f:facet name="errorMarker">
								<h:graphicImage value="/images/error.png" />
							</f:facet>
						</rich:message>
					</h:panelGroup>
					
					<h:panelGroup />
						<h:panelGroup />
						<h:panelGroup>
							<a4j:commandButton value="#{msg.process_bt_edit}"
								action="#{processBean.editAction}">
								<f:setPropertyActionListener target="#{processBean.currentState}"
									value="list" />
							</a4j:commandButton>

							<a4j:commandButton value="#{msg.cancel}" action="process"
								immediate="true">
								<f:setPropertyActionListener target="#{processBean.currentState}"
									value="list"></f:setPropertyActionListener>
							</a4j:commandButton>
						</h:panelGroup>
				</h:panelGrid>
			</h:form>
			</rich:panel>
		</a4j:outputPanel>
		
				<a4j:outputPanel id="remove" rendered="#{processBean.currentState == 'remove'}">
		
			<h1><h:outputText value="#{msg.process_remove_title}" /></h1>
			<rich:panel>
			<h5><h:outputText value="#{msg.confirmRemoveProcess}" /></h5>
			<h:form>
			<h:panelGrid columns="2" cellspacing="4">
					
					<h:outputLabel value="#{msg.process_name}" />
					<h:outputText id="process_name" value="#{processBean.name}" />

					<h:outputLabel value="#{msg.process_number}" />
					<h:outputText id="process_number" value="#{processBean.number}" />
					
					<h:outputLabel value="#{msg.process_part}" />
					<h:outputText value="#{processBean.user.name}" />
					
					<h:outputText value ="#{msg.process_status}" />
					<h:outputText value="#{processBean.status}" />
						
					<h:outputLabel value="#{msg.process_solicitation}" />
					<h:outputText value="#{processBean.solicitation}" />
					
					<h:panelGroup />
					<h:panelGroup />
						<h:panelGroup>
							<a4j:commandButton value="#{msg.process_bt_remove}"
								action="#{processBean.removeAction}">
								<f:setPropertyActionListener target="#{processBean.currentState}"
									value="list" />
							</a4j:commandButton>

							<a4j:commandButton value="#{msg.cancel}" action="process"
								immediate="true">
								<f:setPropertyActionListener target="#{processBean.currentState}"
									value="list"></f:setPropertyActionListener>
							</a4j:commandButton>
						</h:panelGroup>
				</h:panelGrid>
			</h:form>
			</rich:panel>
		</a4j:outputPanel>
		
	<a4j:outputPanel id="list" rendered="#{processBean.currentState == 'list'}">
		<h1><h:outputText value="#{msg.manageProcesses}" /></h1>
			<a4j:form>

				<rich:dataTable value="#{processBean.allProcess}" var="process" columns="6" width="100%" >

					<f:facet name="header">

						<h:outputText value="#{msg.process_table_title}" />

					</f:facet>

					<rich:column>

						<f:facet name="header"><h:outputText value="#{msg.process_name}" /> </f:facet>
						<h:outputText value="#{process.name}" />
					</rich:column>

					<rich:column>

						<f:facet name="header"><h:outputText value="#{msg.process_number}" /></f:facet>

						<h:outputText value="#{process.number}" />

					</rich:column>

					<rich:column>

						<f:facet name="header"><h:outputText value="#{msg.process_solicitation}" /></f:facet>

						<h:outputText value="#{process.solicitation}" />

					</rich:column>
					
					<rich:column>

						<f:facet name="header"><h:outputText value="#{msg.process_part}" /></f:facet>

						<h:outputText value="#{process.user.name}" />

					</rich:column>
					
					<rich:column>

						<f:facet name="header"><h:outputText value="#{msg.process_status}" /></f:facet>

						<h:outputText value="#{process.status}" />

					</rich:column>
					
					<rich:column>

						<f:facet name="header"><h:outputText value="#{msg.process_edit}" /></f:facet>
						
						<a4j:commandButton image="images/bt_edit.png" action="#{processBean.prepareEdit}"><f:setPropertyActionListener value="#{process}"
									target="#{processBean.process}" /></a4j:commandButton>
						<a4j:commandButton image="images/bt_delete.png" action="#{processBean.prepareRemove}"><f:setPropertyActionListener value="#{process}"
									target="#{processBean.process}" /></a4j:commandButton>
												
					</rich:column>

					<f:facet name="footer">

						<h:outputText
							value="" />

					</f:facet>

				</rich:dataTable>


			</a4j:form>
			
	</a4j:outputPanel>
	
	
	</ui:define>

</ui:composition>

</html>